import {defineStore} from 'pinia'
import {ref} from "vue"

export const useNavMenuStore = defineStore('navMenu', () => {
    const menuItems = ref([
        {
            name: '员工管理',
            icon: "iconfont icon-guanliyuan_guanliyuanliebiao",
            path: '/admin/employee',
            children: [
                {
                    name: '员工列表',
                    path: '/list'
                },
                {
                    name: '工单列表',
                    path: '/workorder/list'
                }
            ]
        },
        {
            name: '管理员管理',
            icon: "iconfont icon-guanliyuan_jiaoseguanli",
            path: '/admin/admin',
            children: [
                {
                    name: '管理员列表',
                    path: '/list'
                }
            ]
        },
        {
            name: '游戏管理',
            icon: "iconfont icon-youxi",
            path: '/admin/game',
            children: [
                {
                    name: '游戏列表',
                    path: '/list'
                }
            ]
        },
        {
            name: '游戏分类管理',
            icon: "iconfont icon-fenlei",
            path: '/admin/game/category',
            children: [
                {
                    name: '游戏分类列表',
                    path: '/list'
                }
            ]
        },
        {
            name: '用户管理',
            icon: "iconfont icon-yonghu",
            path: '/admin/user',
            children: [
                {
                    name: '用户列表',
                    path: '/list',
                },
                {
                    name: '用户账单列表',
                    path: '/bill/list'
                }
            ]
        },
        {
            name: '新闻管理',
            icon: "iconfont icon-xinwen",
            path: '/admin/news',
            children: [
                {
                    name: '新闻列表',
                    path: '/list'
                }
            ]
        },
        {
            name: '发行商管理',
            icon: "iconfont icon-gongzuoshi",
            path: '/admin/publisher',
            children: [
                {
                    name: '发行商列表',
                    path: '/list'
                }
            ]
        }
    ])
    const findAllNamesAndPathsByPath = (path) =>
    {
        const results = [];
        function search(items, basePath = '') {
            for (const item of items) {
                const currentPath = basePath + item.path;
                if (path.startsWith(currentPath)) {
                    results.push({name: item.name, path: currentPath});
                    // 继续向下搜索符合条件的子菜单项
                    if (item.children && item.children.length > 0) {
                        search(item.children, currentPath);
                    }
                }
            }
        }
        search(menuItems.value);
        return results;
    }
    return {
        menuItems,
        findAllNamesAndPathsByPath
    }
})
